/**
*@class sslvision
*@brief class rhar fetches info from the network and broadcasts to the location.
*@author Clymans Kevin
*@date 04-2011
* 
* @section source Sources
* From the networkcard, udp packets that get transmitted by the ssl-vision host.
*
* @section working What does the code
* Fetchs packets, unpack them, update location class.
*
* @section destination Destination
* Location.h
*
*/

#ifndef SSLVSION_H
#define	SSLVSION_H
#include <iostream>
#include <string>
#include "proto/messages_robocup_ssl_detection.pb.h"
#include "proto/messages_robocup_ssl_geometry.pb.h"
#include "proto/messages_robocup_ssl_wrapper.pb.h"
#include "proto/robocup_ssl_client.h"
#include "thread.h"
#include "log.h"
#include <set>
#include "myObserver.h"


class sslvision : public Thread{

    /**
     * @brief pointer to Static object
     */
    static sslvision* instance;
    /**
     * @brief interal use of observer.
     */
    set<myObserver*> observers;

public:
    /**
     * @brief start class from threat
     * @sa threat.h
     */
    void run();
    /**
     * @brief Print debug robot info, not usefull for bigger program.
     * @param location of a robot instance.
     */
    void printRobotInfo(const SSL_DetectionRobot& robot);
    //observers
    /**
     * @brief fetch instance for observer pattern
     */
    static sslvision* getInstance();
    /**
     * @brief add an observer
     * @param something that needs to be observed, our case a location class.
     */
    void addObserver(myObserver& o);
    /**
     * @brief remove observer
     * @param thing to be removed from the queue, our case a location class.
     */
    void removeObserver(myObserver& o);
    /**
     * @brief notify all the observers in the queue and update the data.
     */
    void notifyObservers();
private:
    //general IO
    int i;
    int ident;
    Log *logger;
    char *temp;
    //Basic file formats
    RoboCupSSLClient client;
    SSL_WrapperPacket packet;
    SSL_DetectionFrame detection;

    //received data in frame
    //time now
    double t_now;
    //general info and latency
    int camera_id;
    int frame;
    float capture;
    float latency_proc;
    float latency_net;
    float latency_tot;

    //robot detection
    int robots_blue_n;
    int robots_yellow_n;
    SSL_DetectionRobot robotb1;
    SSL_DetectionRobot robotb2;
    SSL_DetectionRobot roboty1;
    SSL_DetectionRobot roboty2;
    
    //ball info
    int balls_n;
    SSL_DetectionBall ball;

    //geo data
    int calib_n;

    /**
     * @brief internal for observer pattern
     */
    void trigger();
    
};

#endif	/* SSLVSION_H */

